package com.chen.springboot.dto;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.chen.springboot.entity.RefundOrder;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @Author Chen
 * @Date 2024/12/17 14:06
 */
@Data
public class RefundOrderDto {
    @ExcelProperty(value = "订单编号", index = 0)
    private String orderNo;
    @ExcelProperty(value = "退款金额￥", index = 1)
    private BigDecimal refundAmount;
    @ExcelProperty(value = "退款原因", index = 2)
    private String refundReason;
    @ExcelProperty(value = "退款时间", index = 3)
    private Date refundDate;
    // 原始的 refundType 字段，将被忽略
    @ExcelIgnore
    private Integer refundType;
    // 新增的 refundTypeString 字段，用于 Excel 导出
    @ExcelProperty(value = "退款形式", index = 4)
    private String refundTypeString;
    @ExcelProperty(value = "退款人", index = 5)
    private String username;

    public RefundOrderDto(RefundOrder refundOrder) {
        this.orderNo = refundOrder.getOrderNo();
        this.refundAmount = refundOrder.getRefundAmount();
        this.refundReason = refundOrder.getRefundReason();
        this.refundDate = refundOrder.getRefundDate();
        this.username = refundOrder.getUsername();
        this.refundType = refundOrder.getRefundType();
    }

    public String getRefundTypeString() {
        if (refundType == null) {
            return "";
        }
        switch (refundType) {
            case 1:
                return "未发货退款";
            case 2:
                return "退货退款";
            default:
                return "未知类型";
        }
    }

    // setter 方法，用于设置 refundType
    public void setRefundType(Integer refundType) {
        this.refundType = refundType;
        // 当 refundType 被设置时，同时更新 refundTypeString
        this.refundTypeString = getRefundTypeString();
    }
}
